package com.decent.ejfadmin.product.dao;


import com.decent.ejfadmin.common.bean.SupplyProduct;
import com.decent.ejfadmin.common.bean.SupplyProductPrice;
import com.decent.ejfadmin.product.dao.provider.SupplyProductProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.stereotype.Repository;

/**
 * describe:
 *
 * @author JunLei He
 * @date 2018年07月11日
 */
@Mapper
@Repository
public interface SupplyProductDao {


    /**
     * 查询折扣
     *
     * @param modelId   价格模板id
     * @param productId 产品id
     * @return 返回
     */
    @Select("  SELECT " +
            " map.min_price * 10 minPrice, " +
            " map.max_price * 10 maxPrice, " +
            " map.state  " +
            "FROM " +
            " yuhuang_supply_model m, " +
            " yuhuang_supply_model_price_map map " +
            "WHERE " +
            " map.model_id = m.id " +
            "and map.model_id=#{modelId} " +
            "and map.product_id=#{productId} ")
    SupplyProductPrice queryProductPrice(@Param("modelId") Long modelId,
                                         @Param("productId") Long productId);

    /**
     * @param userId    用户id
     * @param productId 产品id
     * @return 返回
     */
    @Select("SELECT " +
            " p.min_price * 10 minPrice, " +
            " p.max_price * 10 maxPrice, " +
            " p.state " +
            "FROM " +
            " yuhuang_user_product_price p " +
            "WHERE " +
            " p.product_id =  #{productId} " +
            "AND p.user_id =  #{userId} ")
    SupplyProductPrice queryUserProductPrice(@Param("userId") Long userId,
                                             @Param("productId") Long productId);

    /**
     * 查询产品信息
     *
     * @param area        地区
     * @param face        面值
     * @param productType 产品类型
     * @return 返回产品信息
     */
    @SelectProvider(type = SupplyProductProvider.class, method = "queryProduct")
    SupplyProduct queryProduct(@Param("area") String area, @Param("face") Integer face, @Param("productType") Integer productType);


}
